<?php
class myUser extends sfBasicSecurityUser
{
    public function addBookCopyToHistory (Inventory $bookCopy)
    {
        $ids = $this->getAttribute('bookcopies_history', array());
        if (! in_array($bookCopy->getId(), $ids)) {
            array_unshift($ids, $bookCopy->getId());
            $this->setAttribute('bookcopies_history', array_slice($ids, 0, 3));
        }
    }
    public function getBookCopiesHistory ()
    {
        $ids = $this->getAttribute('bookcopies_history', array());
        if (! empty($ids)) 
        {
            return Doctrine::getTable('Inventory')
                ->createQuery('a')
                ->whereIn('a.id', $ids)
                ->execute();
        } 
        else 
        {
            return array();
        }
    }
    
    public function resetJobHistory()
    {
        $this->getAttributeHolder()->remove('bookcopies_history');
    }
    
}
